package com.java.miaosha.service.impl;

import com.java.miaosha.entity.OrderEntity;
import com.java.miaosha.entity.UserEntity;
import com.java.miaosha.service.MiaoshaGoodsService;
import com.java.miaosha.service.MiaoshaService;
import com.java.miaosha.service.OrderService;
import com.java.miaosha.vo.GoodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author jiangli
 * @date 2019/8/31 21:45
 */
@Service
public class MiaoshaServiceImpl implements MiaoshaService {
	@Autowired
	private OrderService orderService;
	@Autowired
	private MiaoshaGoodsService miaoshaGoodsService;

	@Override
	@Transactional
	public OrderEntity miaosha(UserEntity user, GoodsVO goods) {
		//减秒杀库存 下订单 写入秒杀订单
		if (miaoshaGoodsService.reduceStock(goods.getId())) {
			return orderService.createOreder(user,goods);
		} else {
			return null;
		}

	}
}
